<template>
    <div class="person-card" >
      <div class="info">
        <HeadPortrait :imageUrl="personInfo.avatar" />
        <div class="info-detail">
          <div class="name">{{ personInfo.name + " [" + formattedTime + "]" }}</div>
          <div class="detail">{{ personInfo.message }}</div>
        </div>
      </div>
    </div>
</template>
  
<script>
import HeadPortrait from "./HeadPortrait.vue";
import {computed} from 'vue'
import { DateTime } from 'luxon'

export default {
  props: {
    personInfo: {
      message: "",
      name: "",
      avatar: "",
      role: "",
      timestamp: 0,
    }
  },
  components: {
    HeadPortrait,
  },
  setup(props) {
    const formattedTime = computed(() => {
      const date = DateTime.fromMillis(props.personInfo.timestamp * 1000, { zone: 'Asia/Shanghai' })
      return date.toFormat('yyyy-MM-dd HH:mm:ss')
    })

    return {
      formattedTime,
    }
  }
};
</script>

<style lang="scss" scoped>
.person-card {
  width: 40%;
  height: auto;
  border-radius: 10px;
  background-color: #202020;
  position: relative;
  margin: 25px 0;
  cursor: pointer;
  .info {
    display: flex;
    align-items: flex-start; 
    padding: 10px; 
    width: 100%; 
    .head-portrait {
      min-width: 50px;
      max-width: 50px;
    }
    .info-detail {
      margin-left: 20px;
      max-width: calc(100% - 70px);
      .name {
        color: #767676;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        margin-bottom: 5px;
      }
      .detail {
        color: #e8e8e8;
        overflow: hidden;
        white-space: normal;
        overflow-wrap: break-word;
        font-size: 12px;
        max-width: 100%;
        margin-right: 15px;
        line-height: 1.5;
        font-size: medium;
      }
    }
  }
  &:hover {
    background-color: #264b6c;
    transition: 0.3s;
    box-shadow: 0px 0px 10px 0px rgba(0, 136, 255);
    .info {
      .info-detail {
        .detail {
          color: #fff;
        }
      }
    }
  }
}
</style>